package com.my.geojson.test.simple.cvs;

import org.geotools.data.DataUtilities;
import org.geotools.feature.SchemaException;
import org.geotools.feature.simple.SimpleFeatureTypeBuilder;
import org.geotools.referencing.crs.DefaultGeographicCRS;
import org.opengis.feature.simple.SimpleFeatureType;
import org.opengis.geometry.Geometry;

/**
 * 要素类型
 * 要素类型是一个shp文件的约束，类似于数据库的表结构。
 * 在要素类型中，我们主要定义了要素的类型(包括点、线或者面)、投影信息和其他属性信息。
 */
public class FeatureType {

    //创建要素类型
    private static SimpleFeatureType createFeatureTypeByStr() throws SchemaException {
        //the_geom" must be of type Point, MultiPoint, MuiltiLineString, MultiPolygon
        //the_geom" is always first, and used for the geometry attribute name
        return DataUtilities.createType("Location",
                "the_geom:Point:srid=4326,name:String,number:Integer");
    }
    //创建要素类型
    public static SimpleFeatureType createFeatureType(
            Class<? extends Geometry> geometryClazz) {
        SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder();
        builder.setName("Location");
        // <- Coordinate reference system
        builder.setCRS(DefaultGeographicCRS.WGS84);

        // add attributes in order
        builder.add("the_geom", geometryClazz);
        // <- 15 chars width for name field
        builder.length(15).add("Name", String.class);
        builder.add("number", Integer.class);
        // build the type
        return builder.buildFeatureType();
    }

}
